<template>
  <div>
    <!--          “面包屑”-->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">水产品类</a></el-breadcrumb-item>
    </el-breadcrumb>
    <!--          搜索框-->
    <div style="padding: 10px 0;margin-top: 10px">
      <el-input style="width: 125px; margin-left: 5px" placeholder="请输入菜品名字" v-model="name" clearable></el-input>
      <el-button style="margin-left: 5px" @click="load" circle>
        <el-icon><Search /></el-icon>
      </el-button>
      <el-button style="margin-left: 20px" type="warning" @click="reset" plain>
        <el-icon><Refresh /></el-icon>
        <span>重置</span>
      </el-button>
    </div>

    <!--          |右侧主体内容|-->
    <!--          列属性-->
    <el-card style="margin-top:10px">
      <el-table :data="tableData"
                stripe
                style="width: 100%">
        <!--      <el-table-column prop="picture" label="菜品展示" width="140"></el-table-column>-->
        <el-table-column prop="name" label="菜品名称" width="120"></el-table-column>
        <el-table-column prop="material" label="菜品原料" width="120"></el-table-column>
        <el-table-column prop="price" label="菜品价格"></el-table-column>
        <el-table-column prop="popularity" label="菜品热度"></el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button type="warning" style="min-height: 20px;min-width: 20px;text-align: center" @click="handle_add(scope.row)" circle>
              <el-icon><Plus /></el-icon>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>


    <!--          分页组件-->
    <div style="padding: 10px 0;text-align: center;margin-top: 20px">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import { Search, Refresh, Plus } from '@element-plus/icons-vue'

export default {
  name: "Pork",
  components: {
    Search,
    Refresh,
    Plus
  },
  data() {
    return{
      tableData:[],
      total: 0,
      pageNum: 1,
      pageSize: 5,
      picture: "",
      name: "",
      price: 0.0,
      popularity: 0,
      form: {},
      username: localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")):{},
    }
  },
  created() {
    this.load();
  },
  methods: {
    load(){
      // 请求分页相关数据
      request.get("/client/dish/select",{
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          type: 3,    //type = 3，表示蔬菜类
          name:this.name,
        }
      }).then(res =>{
        console.log(res.content);
        this.tableData = res.content.data;
        this.total = res.content.total;
      })
    },
    reset(){
      this.name="";
      this.load();
    },
    handleCurrentChange(pageNum){
      this.pageNum=pageNum;
      this.load();
    },
    // 设置监听页面变化函数,修改pageSize的值
    handleSizeChange(pageSize){
      this.pageSize=pageSize;     //监听页面变化
      this.load();                //页面变化后重新加载数据
    },
    handle_add(row){
      console.log(row);
      this.form = row;
      request.post("/client/dish/add",this.form,{
        params:{
          username: this.username
        }
      }).then(res=>{
        this.$message.info(res.message);
      })
    }
  }

}

</script>

<style scoped>

</style>